package topo;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

import topo.action.AutoDiscoverByIPRoamingAction;
import topo.action.AutoDiscoverByIpAction;
import topo.action.AutoDiscoverByNetAction;
import topo.action.AutoDiscoverByRouterAction;
import topo.action.NodeAddAction;
import topo.action.Proxy;

public class MenuBarManager {
    public static JMenu addDevice = new JMenu("手动添加设备(A)");

    public static JMenu autoDevice = new JMenu("自动搜索设备(S)");

    public static JMenu netLayout = new JMenu("网络重新布局(V)");
    private static JMenuBar menubar;

    public static void initMenu(JMenuBar theMenubar, TopoGraphView topoView) {
        addDevice.setMnemonic('a');
        menubar = theMenubar;
        addDevice(topoView);
        autoDevice(topoView);
        netLayout(topoView);
    }

    private static void addDevice(TopoGraphView topoView) {
        autoDevice.setMnemonic('s');
        menubar.add(addDevice);
        NodeAddAction nodeAddAction = new NodeAddAction();
        nodeAddAction.putValue("ActionDataTopoview", topoView);
        Proxy proxy = new Proxy();
        proxy.putValue("ActionDataTopoview", topoView);
        addDevice.add(nodeAddAction);
        addDevice.add(proxy);
    }

    private static void autoDevice(TopoGraphView topoView) {
        netLayout.setMnemonic('v');
        menubar.add(autoDevice);
        AutoDiscoverByIpAction discoverByIPAction = new AutoDiscoverByIpAction();
        discoverByIPAction.putValue("ActionDataTopoview", topoView);
        autoDevice.add(discoverByIPAction);

        AutoDiscoverByNetAction discoverByNetAction = new AutoDiscoverByNetAction();
        discoverByNetAction.putValue("ActionDataKeyName", topoView);
        autoDevice.add(discoverByNetAction);

        AutoDiscoverByRouterAction discoverByRouteAction = new AutoDiscoverByRouterAction();
        discoverByRouteAction.putValue("ActionDataKeyName", topoView);
        autoDevice.add(discoverByRouteAction);

        AutoDiscoverByIPRoamingAction discoverByIPRoamingAction = new AutoDiscoverByIPRoamingAction();
        discoverByIPRoamingAction.putValue("ActionDataKeyName", topoView);
        autoDevice.add(discoverByIPRoamingAction);
    }

    private static void netLayout(final TopoGraphView topoView) {
        menubar.add(netLayout);

        netLayout.add(new AbstractAction("Hierarchical布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.hierarchicalLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("快速Organic布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.fastOrganicLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("Organic布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.organicLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("Self-Organizing布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.selfOrganicLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("紧凑树型布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.compactTreeLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("放射树形布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.radialTreeLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("基本树形布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.treeLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("Organizational布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.organizationalLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("Spring布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.springLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("简单随机布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.simpleRandomLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("简单标题布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.simpleTiltLayout(topoView);
            }
        });
        netLayout.add(new AbstractAction("圆形布局") {
            public void actionPerformed(ActionEvent e) {
                TopoLayoutManager.simpleCircleLayout(topoView);
            }
        });
    }
}